package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlInformation;
import com.ruoyi.dl.service.IDlInformationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信息Controller
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/dl/information")
public class DlInformationController extends BaseController
{
    private String prefix = "dl/information";

    @Autowired
    private IDlInformationService dlInformationService;

    @RequiresPermissions("dl:information:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/information";
    }

    /**
     * 查询信息列表
     */
    @RequiresPermissions("dl:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlInformation dlInformation)
    {
        startPage();
        List<DlInformation> list = dlInformationService.newSelectDlInformationList(dlInformation);
        return getDataTable(list);
    }

    /**
     * 导出信息列表
     */
    @RequiresPermissions("dl:information:export")
    @Log(title = "信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlInformation dlInformation)
    {
        List<DlInformation> list = dlInformationService.selectDlInformationList(dlInformation);
        ExcelUtil<DlInformation> util = new ExcelUtil<DlInformation>(DlInformation.class);
        return util.exportExcel(list, "information");
    }

    /**
     * 新增信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存信息
     */
    @RequiresPermissions("dl:information:add")
    @Log(title = "信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlInformation dlInformation)
    {
        return toAjax(dlInformationService.insertDlInformation(dlInformation));
    }

    /**
     * 修改信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DlInformation dlInformation = dlInformationService.selectDlInformationById(id);
        mmap.put("dlInformation", dlInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存信息
     */
    @RequiresPermissions("dl:information:edit")
    @Log(title = "信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlInformation dlInformation)
    {
        return toAjax(dlInformationService.updateDlInformation(dlInformation));
    }

    /**
     * 删除信息
     */
    @RequiresPermissions("dl:information:remove")
    @Log(title = "信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlInformationService.deleteDlInformationByIds(ids));
    }
}
